<template>
  <div class="email-editor-container">
    <!-- 顶部操作按钮 -->
    <div class="editor-toolbar">
      <div class="toolbar-group">
        <button class="tool-button" v-for="(item, index) in topButtons" :key="index">
          <i :class="`iconfont ${item.icon}`"></i>
          <span>{{ item.text }}</span>
        </button>
      </div>
    </div>

    <!-- 收件人区域 -->
    <div class="recipient-area">
      <div class="recipient-main-row">
        <div class="recipient-row">
          <span class="recipient-label">收件人</span>
          <input type="text" class="recipient-input" placeholder="多个收件人用分号 ; 分隔">
        </div>
        <div class="recipient-options">
          <div class="recipient-option">
            <span class="recipient-option-label">抄送</span>
            <input type="text" class="recipient-option-input">
          </div>
          <div class="recipient-option">
            <span class="recipient-option-label">密送</span>
            <input type="text" class="recipient-option-input">
          </div>
          <div class="recipient-option">
            <span class="recipient-option-label">分别发送</span>
            <input type="text" class="recipient-option-input">
          </div>
        </div>
      </div>
    </div>

    <!-- 主题 -->
    <div class="subject-row">
      <span class="subject-label">主题</span>
      <input type="text" class="subject-input">
    </div>

    <!-- 编辑器工具栏 -->
    <div class="editor-toolbar secondary-toolbar">
      <div class="toolbar-group">
        <button class="tool-button" v-for="(item, index) in editorButtons" :key="index">
          <i :class="`iconfont ${item.icon}`" v-if="item.icon"></i>
          <span v-if="item.text">{{ item.text }}</span>
          <span class="button-separator" v-if="item.separator"></span>
        </button>
      </div>
    </div>

    <!-- 编辑器内容区 -->
    <div class="editor-content" contenteditable="true" ref="editor">
      <p>输入正文</p>
    </div>

    <!-- 底部状态栏 -->
    <div class="editor-footer">
      <div class="footer-left">
        <span class="word-count">0字</span>
      </div>
      <div class="footer-right">
        <button class="footer-button">
          <i class="iconfont icon-jianpan"></i>
          <span>全屏</span>
        </button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';

const editor = ref(null);

const topButtons = [
  { icon: 'icon-fasong', text: '发送' },
  { icon: 'icon-yulan', text: '预览' },
  { icon: 'icon-fujian', text: '附件' },
  { icon: 'icon-chaodafujian', text: '超大附件' },
  { icon: 'icon-shezhi', text: '发信设置' }
];

const editorButtons = [
  { icon: 'icon-tupian', text: '图片' },
  { icon: 'icon-charu', text: '插入' },
  { icon: 'icon-wendang', text: '导入文档' },
  { icon: 'icon-richeng', text: '日程' },
  { icon: 'icon-biaoqing', text: '表情' },
  { icon: 'icon-ziti', text: 'Aa 格式' },
  { separator: true },
  { text: '默认字体' },
  { text: '字号' },
  { icon: 'icon-bold', text: 'B' },
  { icon: 'icon-italic', text: 'I' },
  { icon: 'icon-underline', text: 'U' },
  { icon: 'icon-strikethrough', text: 'S' },
  { icon: 'icon-font-color', text: 'A' },
  { icon: 'icon-bg-color', text: 'D' },
  { icon: 'icon-align-left', text: 'E' },
  { icon: 'icon-align-center', text: 'F' },
  { icon: 'icon-align-right', text: 'G' },
  { icon: 'icon-list-ul', text: 'H' },
  { icon: 'icon-list-ol', text: 'I' },
  { icon: 'icon-outdent', text: 'J' },
  { icon: 'icon-indent', text: 'K' },
  { icon: 'icon-link', text: 'L' },
  { icon: 'icon-unlink', text: 'M' },
  { icon: 'icon-table', text: 'N' },
  { icon: 'icon-hr', text: 'T' },
  { icon: 'icon-undo', text: 'Y' },
  { icon: 'icon-redo', text: 'Z' },
  { icon: 'icon-eraser', text: 'X' },
  { icon: 'icon-code', text: 'Y' },
  { icon: 'icon-quote', text: 'Z' }
];
</script>

<style scoped lang="scss">
.email-editor-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  background-color: #fff;
  border: 1px solid #ddd;
  border-radius: 4px;
}

.editor-toolbar {
  padding: 8px 16px;
  background-color: #f5f5f5;
  border-bottom: 1px solid #e8e8e8;

  &.secondary-toolbar {
    background-color: #fff;
    padding: 4px 16px;
    border-bottom: 1px solid #eee;
  }
}

.toolbar-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
}

.tool-button {
  display: flex;
  align-items: center;
  padding: 4px 8px;
  background: none;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  font-size: 12px;
  color: #333;
  border: 1px lightgrey solid;

  &:hover {
    background-color: rgb(218, 235, 253)
  }

  .iconfont {
    margin-right: 4px;
    font-size: 14px;
  }
}

.button-separator {
  width: 1px;
  height: 16px;
  background-color: #ddd;
  margin: 0 4px;
}

.recipient-area {
  padding: 8px 16px;
  border-bottom: 1px solid #eee;
}

.recipient-main-row {
  display: flex;
  align-items: center;
  gap: 16px;
}

.recipient-row {
  display: flex;
  align-items: center;
  flex: 1;
}

.recipient-label {
  width: 60px;
  font-size: 13px;
  color: #666;
}

.recipient-input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 13px;
  padding: 4px 8px;

  &::placeholder {
    color: #bbb;
  }
}

.recipient-options {
  display: flex;
  gap: 8px;
}

.recipient-option {
  display: flex;
  align-items: center;
}

.recipient-option-label {
  font-size: 13px;
  color: #666;
  margin-right: 4px;
}

.recipient-option-input {
  width: 120px;
  border: none;
  outline: none;
  font-size: 13px;
  padding: 4px 8px;
  border-bottom: 1px solid #eee;
}

.subject-row {
  display: flex;
  align-items: center;
  padding: 8px 16px;
  border-bottom: 1px solid #eee;
}

.subject-label {
  width: 60px;
  font-size: 13px;
  color: #666;
}

.subject-input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 13px;
  padding: 4px 8px;
}

.editor-content {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  font-size: 14px;
  line-height: 1.5;
  outline: none;

  p {
    margin: 0;
    color: #999;
  }
}

.editor-footer {
  display: flex;
  justify-content: space-between;
  padding: 8px 16px;
  background-color: #f5f5f5;
  border-top: 1px solid #e8e8e8;
  font-size: 12px;
  color: #999;
}

.footer-button {
  display: flex;
  align-items: center;
  background: none;
  border: none;
  cursor: pointer;
  color: #666;

  .iconfont {
    margin-right: 4px;
    font-size: 14px;
  }

  &:hover {
    color: #1890ff;
  }
}
</style>
